package msu.erdc.hci;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class LoginActivity extends Activity {
	
	private EditText passwordView;
	private Button loginButton;
	private TextView forgotPassword;
	private String hardcodedPassword = "password";
	private String hardcodedHint = "The password is password";
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        
        passwordView = (EditText) findViewById(R.id.passwordView);
        
        loginButton = (Button) findViewById(R.id.loginButton);
        loginButton.setOnClickListener(new OnClickListener(){

			public void onClick(View v) {
				if(passwordView.getEditableText().toString().equalsIgnoreCase(hardcodedPassword))
				{
					LoginActivity.this.startActivity(new Intent(LoginActivity.this, AccidentHelperActivity.class));
					finish();//closes this page so pressing back on the main page won't take you back to login screen
				}
				else
					Toast.makeText(LoginActivity.this, "Invalid Password", Toast.LENGTH_SHORT).show();
			}});
        
        forgotPassword = (TextView) findViewById(R.id.forgotPassword);
        forgotPassword.setOnClickListener(new OnClickListener(){

			public void onClick(View v) {
				new AlertDialog.Builder(LoginActivity.this)
				.setMessage("Hint:" + hardcodedHint)
				.setNegativeButton("Close", new DialogInterface.OnClickListener() {
					
					public void onClick(DialogInterface dialog, int which) {
						//do nothing
					}
				})
				.setPositiveButton("Reset Password", new DialogInterface.OnClickListener(){

					public void onClick(DialogInterface dialog, int which) {
						Toast.makeText(LoginActivity.this, "Email Sent", Toast.LENGTH_SHORT).show();
					}})
				.setTitle("Forgot Password")
				.setIcon(android.R.drawable.ic_dialog_info)
				.show();
			}});
    }

}
